//
//  BaseNavgationViewController.m
//  theUnmannedClass
//
//  Created by apple on 2019/6/19.
//  Copyright © 2019 apple. All rights reserved.
//

#import "BaseNavgationViewController.h"
#import "UIView+Extension.h"
#import "UIDevice+VGAddition.h"


@interface BaseNavgationViewController ()<UIGestureRecognizerDelegate>
@property(nonatomic,strong) UIButton *btn;


@end

@implementation BaseNavgationViewController


+ (void)load{
    
    [self setUpBase];

}


- (void)viewDidLoad {
    [super viewDidLoad];

    // 获取系统自带d滑动的target对象
    id target = self.interactivePopGestureRecognizer.delegate;
    
    UIScreenEdgePanGestureRecognizer *pan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:target action:@selector(pushViewController:animated:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    self.interactivePopGestureRecognizer.enabled = YES;
    
    
}


#pragma mark -- <初始化>
+(void)setUpBase{
    // 导航栏的背景颜色
    UINavigationBar * bar = [UINavigationBar appearance];
    bar.backgroundColor = [UIColor clearColor];
    [bar setShadowImage:[UIImage new]];
    [bar setTintColor:[UIColor blackColor]];


    //去掉透明后导航栏下边的黑边
    [bar setShadowImage:[[UIImage alloc] init]];
    
    
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    // 设置导航栏字体颜色
    UIColor * navColor = [UIColor blackColor];
    attributes[NSForegroundColorAttributeName] = navColor;
    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:16.0];
    bar.titleTextAttributes = attributes;
    
    
    
    
}

/**
 *  拦截所有控制器的push控制器
 *
 *  @param viewController 即将到来的控制器
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.viewControllers.count > 0) {
        //返回按钮自定义
        UIButton *TastoVersamento = [UIButton buttonWithType:UIButtonTypeSystem];
        [TastoVersamento setImage:[UIImage imageNamed:@"图层 12"] forState:UIControlStateNormal];
        [TastoVersamento addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        [TastoVersamento setFrame:CGRectMake(0, 0, 40, 42)];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:TastoVersamento];
        //影藏BottomBar
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    
    [super pushViewController:viewController animated:animated];
    
}

-(void)backClick{
    
    [self popViewControllerAnimated:YES];
    
}

//// 状态栏为白色
//-(UIStatusBarStyle)preferredStatusBarStyle{
//    return UIStatusBarStyleLightContent;
//}
//- (UIViewController *)childViewControllerForHomeIndicatorAutoHidden{
//    return self.topViewController;
//}



-(UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage{
    /**
     *  设置返回barButton
     */
    _btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    [_btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [_btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    // 设置尺寸
    _btn.size = _btn.currentBackgroundImage.size;
    return [[UIBarButtonItem alloc]initWithCustomView:_btn];
    
}









@end
